Sex-stratified analyses of comorbidities associated with an inpatient delirium diagnosis using real world data

Delirium is a detrimental mental condition often seen in older, hospitalized patients and is currently hard to predict. In this study, we leverage electronic health records (EHR) to identify 7,492 UCSF patients and 19,417 UC health system patients with an inpatient delirium diagnosis and the same number of control patients without delirium. We found significant associations between comorbidities or laboratory values and an inpatient delirium diagnosis, including metabolic abnormalities and psychiatric diagnoses. Some associations were sex-specific, including dementia subtypes and infections. We further explored the associations with anemia and bipolar disorder by conducting longitudinal analyses from the time of first diagnosis to development of delirium, demonstrating a significant relationship across time. Finally, we show that an inpatient delirium diagnosis leads to increased risk of mortality. These results demonstrate the powerful application of the EHR to shed insights into prior diagnoses and laboratory values that could help predict development of inpatient delirium and the importance of sex when making these assessments.


Abstract
Delirium is a detrimental mental condition often seen in older, hospitalized patients and is currently hard to predict.In this study, we leverage electronic health records (EHR) to identify 7,492 UCSF patients and 19,417 UC health system patients with an inpatient delirium diagnosis and the same number of control patients without delirium.We found signi cant associations between comorbidities or laboratory values and an inpatient delirium diagnosis, including metabolic abnormalities and psychiatric diagnoses.Some associations were sex-speci c, including dementia subtypes and infections.We further explored the associations with anemia and bipolar disorder by conducting longitudinal analyses from the time of rst diagnosis to development of delirium, demonstrating a signi cant relationship across time.Finally, we show that an inpatient delirium diagnosis leads to increased risk of mortality.These results demonstrate the powerful application of the EHR to shed insights into prior diagnoses and laboratory values that could help predict development of inpatient delirium and the importance of sex when making these assessments.

Main
Delirium is a clinical diagnosis de ned as uctuating disturbances in attention, awareness, and cognition that develops over a short period of time and is highly prevalent among older inpatient populations, with an estimated prevalence of 23% in hospitalized older adults 1,2 .Both long-and short-term outcomes of delirium are detrimental to patients, distressing to caregivers, and a burden on the healthcare system [3][4][5] .Notably, patients who are diagnosed with delirium have an increased risk of long-term mortality.It is unclear, however, whether delirium is an independent risk factor for mortality versus other confounding factors are at play such as overall baseline disease burden 3 .Medications for treating delirium are largely for symptomatic management and have not been shown to have clinical bene ts and in fact may lead to worse outcomes, especially for older patients 6 .Prevention is the most effective strategy and often involve non-pharmacological interventions, such as reorientation and cognitive stimulation 7 , making it imperative to predict which patients may develop delirium using predictive tools to focus prevention efforts for high-risk patients.
Though prevalent, delirium remains challenging to study and predict given its heterogenous clinical nature and diverse risk factors 2 .Current prediction tools have variable predictive capabilities, with one systematic review nding an area under the receiver operating curve range from 0.52 to 0.94 8 .These models have other limitations including validation in small sample sizes or data collected from one institution that may not be generalizable [9][10][11] .These models incorporate well-studied risk factors such as existing cognitive impairment and severity of chronic illnesses, but less apparent risk factors also need to be identi ed to improve these predictive tools 8, 12,13 .Importantly, sex is a major risk modi er for many neurological diseases, with some evidence of sexdifferences in delirium [14][15][16] .For instance, one study found hypoactive delirium to be more common in female compared to male patients 15 .Though clinical sex differences have been well-documented in dementia and cognitive impairment --major risk factors for delirium --whether sex differences exist in delirium remains largely unstudied due to the lack of sex-strati ed studies.
One strategy to overcome these limitations is to employ large-scale, comprehensive real-world data from electronic health records (EHR) combined with robust computational approaches.Data from the EHR have been used to better understand and phenotype complex diseases such as Alzheimer's disease, type 2 diabetes, and preterm birth [17][18][19] .Such deep phenotyping studies can shed insights into clinical risk factors and subtypes of disease as well as point to potential new biological pathways that may be involved in disease.
In this study, we leveraged EHRs from two databases across California to identify differential comorbidities and laboratory test results prior to a patient's rst inpatient admission for delirium, which could serve as potential factors in identifying patients at risk for the condition.Importantly, we also conducted a sex-strati ed analysis to identify differences by documented sex in the association between comorbidities or laboratory ndings with a delirium diagnosis.We further analyzed speci c comorbidities using a longitudinal approach to predict the length of time from the diagnosis of a comorbidity and admission for delirium, as an alternative, complementary approach to validate the association study and also provide granularity into the time course from comorbidity diagnosis to delirium diagnosis.Lastly, we conducted a longitudinal analysis to understand the relationship between rst inpatient delirium diagnosis and mortality outcomes.

Identi cation of patients with a diagnosis of delirium and their matched controls
We identi ed 7,492 patients with an inpatient delirium diagnosis and 7,492 propensity-score (PS)matched control patients within the University of California, San Francisco (UCSF) de-identi ed electronic health record (EHR) database (~ 5 million patients total).Propensity score matching was used to create a matched case-control study as individual covariates may not be well-matched but the "propensity" to be either a case or control is well-matched, as illustrated in prior publications justifying this method 20,21 .Control patients were matched on the following demographic and inpatient visit features: age at admission, patient-identi ed race, sex, death during admission, length of the inpatient visit of interest in days, years of available EHR data, total number of inpatient visits prior to the visit of interest, total number of comorbidities prior to the visit of interest, and whether the visit of interest was in the ICU setting.The "visit of interest" corresponded to the visit where an inpatient delirium diagnosis was made for the delirium group or a randomly selected inpatient visit for the control group (Fig. 1).Similarly, a separate cohort of 19,417 patients with an inpatient delirium diagnosis and 19,417 PSmatched control cohort were identi ed from the UC-Wide EHR database (~ 8.6 million patients total, data from UC Davis, UC Los Angeles, UC Irvine, UC San Diego) with an additional matching criterion that included UC location (Fig. 1).These covariates were chosen based on prior EHR-based studies using PSmatched cohort selections with inclusion of additional covariates to control for health status and healthcare utilization frequency using indirect measures such as the total number of inpatient visits and comorbidities prior to the visit of interest and years of available EHR data 17,[22][23][24] .Because patients who develop delirium tend to be at baseline more ill than those who do not develop delirium, we wanted to nd a comparable control group that had similar baseline disease burden and identify what speci c comorbidities are differentially enriched between patients who are similarly "ill", but one group develops delirium and the other group does not.Post-matching analysis showed adequate matching of covariates with similar PS distributions between the groups (Extended Data Fig. 1a,c) and absolute standardized mean differences less than 0.1, except for inpatient stay length which had a wide distribution in both databases (Extended Data Fig. 1b,d).Detailed demographic and inpatient visit features for the cohorts generated are shown in Table 1.We de ned inpatient delirium broadly using the Observational Medical Outcomes Partnership (OMOP) concept ID 373995 (corresponding to "Delirium") and excluded diagnoses that had speci c causes of delirium in the diagnosis name (such as alcohol-induced delirium or other substance-induced delirium).These exclusion criteria were used to focus on cases where a delirium diagnosis was made but the cause of the delirium was not readily known.Using this de nition, we were able to capture 84% and 89% of all delirium-related visits in the UCSF and UC-wide databases, respectively, with delirium prevalence within the wide range of published estimates for patients 65 years and older (9.5% mean, 8.9% SD in UCSF data; 3.5% mean, 1.9% SD in UC-wide data) (Extended Data Fig. 2a,b).We used the Richmond Agitation Sedation Scale (RASS) rating to corroborate the delirium diagnosis in the UC-wide data.RASS is a 10-point rating scale ranging from − 5 to 5, with negative numbers corresponding to the level of sedation and positive numbers corresponding to the level of agitation.
Though RASS is a more general measure of a patient's level of sedation, validated mostly in the ICU setting, it has also been implemented more widely in the inpatient setting for detection of delirium 25,26 .Less than half of patients had documented RASS ratings during their visit of interest.Of the available ratings, patients with delirium had a statistically signi cant increase in the mean RASS rating compared to controls (Extended Data Fig. 2c), suggesting patients with a delirium diagnosis are overall more agitated during the visit and also have greater variability in their RASS ratings (data not shown), suggesting a waxing and waning nature to their clinical status.
Patients with delirium are more likely to be diagnosed with diseases of the nervous system, mental health, metabolic disorders, and infections compared to control patients To understand potential risk factors associated with an inpatient delirium diagnosis, we rst collected all rst-time diagnoses made during visits prior to the inpatient admission of interest.Low-dimensional Uniform Manifold Approximation and Projection (UMAP) representation of all non-delirium diagnoses (19,590 features, SNOMED concept IDs) shows a statistically signi cant separation of patients with a delirium diagnosis versus matched controls by two-sided Mann-Whitney U test (UMAP 1, p-value < 2.2 e-16; UMAP 2 p-value 0.0086; Fig. 2a).
Differential association analyses of these comorbidities using Fisher's exact test showed enrichment of distinct comorbidities for patients with delirium compared to control patients, with 101 diagnoses signi cantly enriched in patients with delirium versus 108 in controls, out of 19,583 diagnoses tested (Fig. 2b).Control patients had enrichment of diagnoses largely related to pregnancy and other health statuses as well as age-related musculoskeletal diagnoses such as pain in joints and osteoarthritis and skin ndings such as melanocytic nevus (Fig. 2b,c, and Supplementary Table 1).Meanwhile, patients with delirium had enrichment of diagnoses related to diseases of the nervous system, including epilepsy and seizures, mental health and behavioral disorders, and acute diagnoses such as metabolic diseases and infections (Fig. 2b,c, and Supplementary Table 1).Similar diagnostic associations were seen in the UC-wide cohort based on a hypergeometric test (p-value 1.2 e-94; Fig. 2d-f, Extended Data Fig. 3, Supplementary Table 2, and Supplementary Table 3).Categorizations of these overlapping diagnoses between the two databases by ICD10 diagnostic blocks showed enrichment of diagnoses related to certain disease categories in patients with delirium versus control patients, including blood-related diseases such as anemia, diseases of the genitourinary system such as urinary tract infections, diseases of the nervous system such as epilepsy, metabolic diseases such as hyponatremia, and mental healthrelated disorders such as bipolar disorder (Extended Data Fig. 3d and Supplementary Table 3).These ndings are largely consistent with previously-identi ed risk factors for delirium 2 .

Differential laboratory ndings corroborate differential associations between comorbidities and delirium
We also conducted enrichment analysis for mean laboratory values and vital signs collected before the inpatient admission of interest.Patients with a delirium diagnosis had signi cantly higher mean values of certain liver function tests, such as alkaline phosphatase and aspartate transferase, compared to controls in both UCSF and UC-wide datasets, suggesting potential liver dysfunction in these patients (Fig. 3a).Elevated mean vital signs included heart rate and respiratory rate (Fig. 3a).Meanwhile, glomerular ltration rate and urine creatinine levels were decreased in patients with delirium compared to controls, consistent with kidney dysfunction (Fig. 3a).Hemoglobin, hematocrit, and erythrocyte counts were also signi cantly decreased in patients with delirium compared to controls, consistent with the association with an anemia diagnosis in these patients (Fig. 3).The UC-wide dataset also captured certain clinical test scores, including results from the Patient Health Questionnaire (PHQ)-2 and PHQ-9, consistent with the associations with depression in these patients (Supplementary Table 4).

Sex-strati ed analysis shows certain infections and dementia subtypes are sex-speci c risk factors for delirium
To understand whether any of the comorbidities associated with delirium that we identi ed are sexspeci c, we conducted a sex-strati ed association analysis using the same cohort identi ed above (Extended Data Fig. 4 and Extended Data Fig. 5).We identi ed several diagnoses that were signi cantly associated with delirium in only females, only males, or in both female and male patients with delirium compared to controls in both UCSF and UC-wide datasets (Extended Data Fig. 4c-e and Extended Data Fig. 5c-e) as well as sex-speci c laboratory results (Extended Data Fig. 4f and Extended Data Fig. 5f).
Diagnoses common to both male and female patients with delirium in both datasets were largely similar to the non-strati ed analysis, including symptoms of delirium such as altered mental status, restlessness and agitation, and hallucinations, as well as known organic causes of delirium and altered mental status such as seizures, cognitive disorders and other mental disorders (Fig. 4c).Interestingly, female and male patients diagnosed with delirium had sex-speci c associations with distinct infections and diseases of the nervous system that were statistically signi cant in both datasets.For instance, female patients with delirium had associations with encapsulated bacterial infections due to Streptococcal bacteria (OR UCSF 2.38; UC-wide 1.61), Klebsiella pneumoniae (OR UCSF 2.95, UC-wide 2.14), Escherichia coli (OR UCSF 1.45, UC-wide 1.81), and enterococcal bacteria (OR UCSF 1.53, UC-wide 1.79), while males had associations with Clostridioides di cile infections (OR UCSF 3.89, UC-wide 1.55) (Fig. 4a,b).Sex-speci c associations with subtypes of dementia were also seen, where females had signi cant associations with Alzheimer's disease (OR UCSF 2.06, UC-wide 3.55) and vascular dementias with behavioral disturbances (OR UCSF 1.89, UC-wide 3.29) while males had associations with Diffuse Lewy Body disease (OR UCSF 1.51, UC-wide 4.22) and diagnoses related to symptoms of the disease such as visual hallucinations, falls, di culty walking / muscle weakness, dysphagia, insomnia, and constipation (Fig. 4a,b, Supplementary Table 5, and Supplementary Table 6).These sex-speci c associations could be because these dementia subtypes are known to have sex-differences in their prevalence already 14 or could point to sex-speci c ways in which delirium manifest in different patient populations.
Though there were several sex-speci c laboratory results found in the UCSF and UC-wide datasets, none were common between the two datasets.Laboratory ndings associated with delirium in both male and female patients as well as between both datasets were similar to the results of the non-sex-strati ed analysis, including decreased hemoglobin and hematocrit consistent with an anemia diagnosis, decreased GFR consistent with kidney dysfunction, elevated liver function tests such as alkaline phosphatase, and elevation of heart rate (Fig. 3a, Extended Data Fig. 4f, and Extended Data Fig. 5f).

Longitudinal analysis from diagnosis of a potential risk factor of delirium to an inpatient delirium diagnosis validates comorbidity association study
To further understand several of the comorbidities associated with an inpatient delirium diagnosis identi ed above, we carried out a longitudinal time-to-event analysis for anemia and bipolar disorder.We chose these diagnoses for analysis given the higher association of blood-related disorders and mental and behavioral disorders in patients with delirium found through our association study (Fig. 2d).Patients with a rst-time diagnosis of anemia and no prior diagnosis of delirium and a matched control group with no diagnosis of anemia and no prior diagnosis of delirium were identi ed.Control patients were matched on the following parameters: age at the visit of interest, patient-identi ed race, documented sex, years of available EHR data, total number of inpatient visits prior to the visit of interest, and total number of comorbidities prior to the visit of interest (Extended Data Fig. 6).Events were de ned as admission for delirium, death, or loss to follow-up.Kaplan-Meier curve visualization of the data showed strati cation by anemia diagnosis status, where those with anemia have increased probability of developing rst-time inpatient delirium diagnosis (UCSF 3.4%, UC-wide 1.3% of anemia patients) than those without any anemia diagnosis (UCSF 0.3%, UC-wide 0.3% of control patients) over the course of ~ 30 years in the UCSF data and ~ 11 years in the UC-wide data (Fig. 5a and Extended Data Fig. 7a).Cox proportional hazard ratio analysis unadjusted and adjusted for demographics and visit features revealed a signi cant increased risk of delirium in those with an anemia diagnosis compared to controls (UCSF HR 9.4; 95% CI, 8.1 to 11; UC-wide HR 4.4; 95% CI, 4.1 to 4.7) (Fig. 5b).A similar analysis was done for patients with and without Bipolar I Disorder (BD1) in UCSF patients or bipolar disorder (unspeci ed type) in UC-wide patients.We found that a diagnosis of BD also increased risk of developing rst-time inpatient delirium diagnosis (UCSF 1.9%, UC-wide 0.7% of BD patients) than those without a BD diagnosis (UCSF 0.01%, UC-wide 0.01% of control patients) with a HR of 27 (95% CI, 9.9 to 74.4) for UCSF patients and HR of 7.8 (95% CI, 6.0 to 10.0) for UC-wide patients over the course of ~ 20 years in the UCSF data and ~ 10 years in the UC-wide data (Fig. 5c,d, and Extended Data Fig. 7b).
Our association studies also found that certain diagnoses are more enriched in control patients compared to patients with delirium, including diagnoses under the ICD10-CM neoplasm category such as melanocytic nevus (Fig. 2d and Supplementary Table 3).We did a similar time-to-event analysis of patients with and without this diagnosis and found that, indeed, a prior diagnosis of melanocytic nevus modestly decreased the risk of developing delirium at a HR of 0.3 (95% CI, 0.2 to 0.5) for UCSF patients and HR of 0.76 (95% CI, 0.67 to 0.86) for UC-wide patients (Fig. 5e,f, and Extended Data Fig. 7c).
A single inpatient delirium admission is associated with increased mortality Previous meta-analyses have documented increased risk of mortality after an inpatient delirium admission 3 .To validate these ndings in a larger population size while also accounting for more covariates than previously tested, including health status, we used our cohort of patients with delirium and their matched controls to conduct a longitudinal time-to-event analysis, where an event was de ned as mortality or loss to follow-up.Kaplan-Meier survival curve visualization of the data showed different probabilities of survival rates between patients with an inpatient delirium admission (median 8.47 years; 95% CI, 7.8 to 9.35 in delirium group) versus control patients (Fig. 6a).Cox proportional hazard ratio analysis unadjusted and adjusted for demographic characteristics (sex, age at admission, race, length of time in EHR, number of inpatient visits prior, total number of comorbidities) and visit features (type of visit, visit length, and length of follow-up time in EHR) revealed a signi cant increased risk of delirium in those with a delirium diagnosis compared to controls (HR 1.2; 95% CI, 1.16 to 1.29) (Fig. 6b).A similar analysis for the UC-wide patient cohort also showed increased mortality in those with a delirium diagnosis compared to controls with a HR of 1.14 (95% CI, 1.1 to 1.18) (median 8.96 years; 95% CI, 8.16 to 10.1 in control group; median 3.83 years; 95% CI, 3.71 to 4.1 in delirium group) (Fig. 6c,d).

Discussion
In the past few decades, clinical data from the EHR combined with integrative computational approaches have enabled the dissection of complex, heterogeneous diseases in an unbiased manner.This study aims to apply this strategy to better understand both risk factors and outcomes of patients who are diagnosed with delirium while in the hospital.We found that many well-known risk factors of delirium emerged through our analysis looking at comorbidities associated with an inpatient delirium diagnosis, including chronic neurological conditions such as dementia and epilepsy as well as acute conditions such as infections and metabolic disturbances.Our sex-strati ed association studies revealed that, even within these large categories of diseases of the nervous system and infections, subtypes of conditions were sex-speci c.We also validated several of these comorbidities associated with delirium, including anemia, bipolar disorder, and melanocytic nevus, through time-to-event analyses.Finally, we showed that a delirium diagnosis is independently associated with an increased risk of mortality, with UCSF and UCwide data showing a median survival of ~ 8.5 and ~ 4 years, respectively.
To our knowledge, this is the rst study to conduct a deep analysis of delirium versus control patients using the EHR data with over 7,000 patients with delirium in the exploratory dataset and ~ 20,000 patients in the validation dataset.We aimed to nd an appropriately matched control cohort by using propensity score matching and including covariates that assess patient health status as well as frequency of healthcare utilization.We also did not exclude patients based on prior cutoffs such as age thresholds or ICU versus non-ICU admissions, as done by previous studies.This strategy enabled us to include as many delirium cases as possible to nd potential associations that may be subtle but meaningful.For instance, anemia before admission for delirium was enriched in delirium patients compared to controls in both UCSF and UC-wide datasets.This was also con rmed at the laboratory level, with signi cant mean hemoglobin difference in patients with and without delirium (11.6 versus 12.2 respectively).Our longitudinal analysis validated our comorbidity analysis and provided an understanding of the time between diagnosis of a risk factor to the development of delirium.In the UCSF data, for instance, roughly 3% of patients with anemia went on to develop delirium within 10 years of the diagnosis while less than 0.5% of patients without anemia developed delirium in this timeframe (hazard ratio of 9.4).One study in 700 patients speci cally undergoing lumbar spinal fusion found that perioperative anemia is a risk factor for developing delirium post-operation 27 .Our study is the rst to show that a diagnosis of anemia may be a more generalizable risk factor for developing inpatient delirium.Further studies need to be done to understand whether treating anemia more aggressively will reduce development of delirium.
The large number of patients also enabled us to dissect the diagnostic associations with delirium in a sex-strati ed manner.Our ndings point to potentially new biological insights into the pathophysiology of delirium that are sex dependent.For instance, male patients had a signi cant association with Clostridioides di cile infections, an infection that often develops after antibiotic use.This could point to either the Clostridioides di cile toxin and the downstream consequences of the infection being associated with delirium or the antibiotic that was used that led to the infection being associated with delirium.Meanwhile, Klebsiella and E. coli infection were enriched in female patients with delirium, organisms that most commonly cause urinary tract infections, a source of infection more common in females compared to males.Dementia, one of the known risk factors of delirium, is also known to have sex-biased features, including in prevalence, clinical progression, and neuropathological ndings 14 .
Interestingly, our association studies found that subtypes of dementia were associated with delirium in a sex-dependent manner.Further studies will need to be done to understand whether this is due to the underlying sex differences in the prevalence of these dementia subtypes or sex differences in the pathophysiology of these dementias contributing to delirium.
There are several limitations to our study that need further investigation.Given that illness-severity is a well-studied risk factor for delirium, we used several indirect metrics of health status, including number of inpatient admissions and number of comorbidities, to nd an appropriately matched control cohort to our delirium cohort.In this way, we were able to compare groups with similar health statuses to extract more subtle risk factors that may be associated with delirium.Though we matched on the number of comorbidities to identify a control cohort with a similar health status, some comorbidities are more functionally debilitating and severe than others.Not all factors relating to delirium, or any condition of interest are captured or measured within the EHR as the data re ects only what is assessed or entered by clinicians.Given our control group had more pregnancy-related diagnoses, this suggests that though the control group may have a similar frequency of healthcare utilization, they are overall healthier than the matched delirium cohort.Future studies could use other health status metrics, such as the Charlson Comorbidity Index, which was not available in the datasets we used, or the American Society of Anesthesiologists (ASA) physical status classi cation score 28 .ASA was available in our UC-wide dataset and was signi cantly higher in patients with delirium compared to control patients (Supplementary Table 4).The mean values, however, were 2.95 in control patients versus 3.05 in delirium patients, suggesting this difference is likely not clinically meaningful, given the scores are integer numbers.
De ning an accurate delirium diagnosis in the EHR is challenging.Detection and clinical diagnosis of delirium itself is often challenging and likely underdiagnosed 2,29 .As a result, the published prevalence of delirium in older patients varies widely, with some estimates around 23% 30 while others as high as 88% in palliative care patients 31 .Prevalence of delirium in our study was lower than these estimates, likely due to our restricted de nition of delirium only including one OMOP concept ID and including younger patients.This de nition, however, likely missed patients that did not t this exact delirium de nition.Documentation of delirium is unfortunately inconsistent in the EHR even with a con rmed diagnosis, with one study nding that only 9 out of 25 cases coded by ICD-9 code 32 .RASS scores were available for some of our patients in the UC-wide dataset and showed scores were different between patients with delirium and controls, suggesting our inclusion criteria is likely consistent with clinical metrics of delirium.We, however, did not use RASS as a way to include or exclude patient as it is not a tool speci c to delirium but rather an overall metric of sedation status.Future studies could include more patients by identifying delirium symptoms in clinical notes or including patients who have been screened for delirium using clinical tools such as the 4 A's Test (4AT) or the confusion assessment method (CAM) 33, 34 , which were not available in the datasets we used.
In this study, the de nition of sex in the EHR is likely a combination of sex assigned at birth, legal sex, and sex determined by the clinician.Documentation of gender identity remains a challenge in the EHR and only recently has garnered attention to provide more inclusive and a rmative health care for all patients 35,36 .Further studies will need to be done to understand whether the associations found in this study are different when taking into context biological sex versus patient-reported gender identity.
Similarly, other social determinants of health were not taken into account in this study, such as the patient's level of formal education, which can in uence cognitive reserve, as well as family / caregiver dynamics.
Overall, our study demonstrates the powerful application of the EHR to study heterogeneous disease processes and to better understand the risk factors and outcomes of disease at both a large patient population scale and a longitudinal time course.These results not only con rmed some of the known risk factors of delirium but also generated several new clinical hypotheses that will need to be further investigated.Applications of these analyses on other data types such as medication history may also expand the potential risk factors for delirium and increase the predictive power for the condition.These ndings could also help develop future modeling studies for predicting which patients will develop delirium to focus prevention efforts towards these patients.Understanding the impact of sex differences in delirium remains understudied, and this study points to the importance of doing sex-strati ed analyses and the potentially interesting pathophysiology of delirium that interacts with sex.

Methods
Resource Availability: Lead Contact: Further information and requests for resources and reagents should be directed to and will be ful lled by the lead contact, Marina Sirota (marina.sirota@ucsf.edu).
Materials availability: This study did not generate new unique reagents.
Data and code availability: The UCSF EHR database is available to individuals a liated with UCSF who can the UCSF's Clinical and Translational Science Institute (CTSI) (ctsi@ucsf.edu) or the UCSF's Information Commons team for more information (Info.Commons@ucsf.edu).The UC-wide EHR database is only available to UC researchers who have completed analyses in their respective UC rst and have provided justi cation for scaling their analyses across UC health centers (more details at https://www.ucop.edu/uc-health/departments/center-for-data-driven-insights-and-innovations-cdi2.html or by contacting healthdata@ucop.edu.The code used for analysis will be made available on Github.Any additional information required to reanalyze the data reported in this paper is available from the lead contact upon request.
Experimental Model and Study Participation Details: All analysis of and UC-wide EHR data was performed under the approval of the Institutional Review Boards.All clinical data were de-identi ed and written informed consent was waived by the institutions.Patient cohorts were identi ed using the UCSF de-identi ed and UC-wide HIPAA-compliant limited data set OMOP EHR databases.The UCSF dataset included over ve million patients from January 1, 1982 to February 20, 2023 while the UC-wide dataset included over seven million patients from January 1, 2012 to April 19, 2023 from 4 sites (UC San Diego, UC Los Angeles, UC Irvine, and UC Davis).Patients with inpatient delirium were identi ed using the OMOP concept ID 373995, SNOMED code 2776000 (corresponding to "Delirium"), ltered for rst-time diagnosis of delirium during an inpatient stay (i.e., 'visit of interest').The inpatient control cohort with no delirium diagnosis was identi ed through propensity score (PS) matching (matchit R 37 ) by a generalized linear model at a 1:1 ratio using a nearest neighbor method and the following matching criteria: assigned sex, patient-reported race, estimated age at admission, years in EHR prior to visit, total number of comorbidities and inpatient visits prior to the visit of interest, stay length, stay type (ICU vs non-ICU), death during admission, and UC location (for UCwide dataset).Propensity score matching was used similar to other previously published works using clinical datasets 17,23,38,39 .For sex strati cation, we utilized reported sex and excluded nonbinary and other categories due to low sample size, similar to a prior study 17 .See Table 1 for cohort demographic details.
Method Details: Differential comorbidity analysis: Comorbidities were identi ed prior to the visit of interest with the earliest entry of every diagnosis.All patients and their comorbidities were visualized using Uniform Manifold Approximation and Projection (UMAP) using the R-implementation of the umap-learn package from Python 40 .UMAP is a form of dimensionality reduction to plot high-dimensional data into a lower-dimension.In this case, a table was created with all distinct comorbidities as columns and all patients as rows, with each table entry corresponding to 0 as the patient not having that diagnosis and 1 as the patient having that diagnosis.This table was then visualized as a UMAP with each point corresponding to one patient and encapsulating the similarity of that patient's comorbidities to other patients based on distance.
Correlations between variables (delirium status or sex) and UMAP coordinates were analyzed using Mann-Whitney U-tests.Differential comorbidity analysis between patients with delirium and controls was done using Fisher's exact test and signi cance determined by Bonferroni-corrected threshold of p-value < 0.05.ICD10-CM blocks were also used to visualize differential comorbidity results.The OMOP concept table was used to map the SNOMED codes to ICD10 codes then mapped to categorical modules using the ICD10 codes.Overlaps between results of analyses using UCSF versus UC-wide datasets were done using hypergeometric test or Spearman correlation.A similar analysis was done for the sex-strati ed analysis.

Differential laboratory test results analysis:
Laboratory test results collected for tests done prior to the visit of interest, and the median values for all numerical lab tests was calculated.Lab tests that had more than 95% of patients missing results were excluded from the analysis, adapted from a prior study 17 .Lab value distributions were compared using Mann-Whitney U-tests across delirium status or sex.

Longitudinal analyses:
Time-to-event analysis was done by rst identifying patients with a diagnosis of bipolar disorder (BD) and no prior delirium diagnosis.PS-matched control cohorts with no diagnosis of BD were identi ed using similar matching-criteria as described above.Time-to-event was calculated as time from rst-time diagnosis of BD (or another non-BD diagnosis for the control patients) to either rst inpatient delirium diagnosis, death, or loss to follow-up.Cox regression model was used to determine the hazard ratio, con dence intervals and signi cance (survival R 41 ).Time-to-event analysis for mortality after delirium was done using a similar strategy.

Quanti cation and Statistical
Schematic of study.Patient cohorts were selected from the OMOP electronic health record databases from UC San Francisco (UCSF) and UC-Wide databases (4 sites: UC Davis, UC San Diego, UC Los Angeles, UC Irvine).All patients and their rst inpatient diagnosis of delirium were selected and a control cohort with no delirium diagnosis was selected using propensity score matching on the features listed in the formula.Association and longitudinal analyses were done using these cohorts.Association studies were done with prior diagnoses and prior laboratory results, with and without sex-strati cation.
Longitudinal analyses included time-to-delirium diagnosis after rst-time diagnosis of selected potential diagnostic risk factor and time-to-mortality outcome after an inpatient delirium diagnosis.See also Table 1.Signi cant comorbidities found in both databases with diagnoses with the largest odds ratios highlighted.See also Extended Data Fig. 3.
Analysis: All statistical analyses were performed R Statistical Software version 4.3.2(R Core Team 2023) and the speci c statistical tests used for each experiment are outlined in detail above in each respective section as well as in the gure legends respectively.Declarations 40.McInnes LH, Melville J (2020) J. UMAP: uniform manifold approximation and projection for dimension reduction.arXiv:1802.0342641.Therneau TMG (2000) P. M. Modeling Survival Data: Extending the Cox ModelNew York

Figure 5 A
Figure 5

Table 1 .
Demographic information of matched cohorts.Table of demographic information for patient cohorts identi ed in UCSF (left) and UC-wide (right) data.Chi-squared test used for categorical measures.Student's t-test used for continuous measures.SMD = standardized mean difference.